//
//  Define.swift
//  LGMusic
//
//  Created by 梁尚嘉 on 2017/3/22.
//  Copyright © 2017年 LimeGah. All rights reserved.
//

import Foundation
import UIKit

func SM_SCREEN_SIZE() -> CGSize{
    return UIScreen.main.bounds.size
}

func SM_SIZE(_ px:CGFloat) -> CGFloat {
     return (px/2)
}

func SM_CFont(_ px:CGFloat) -> UIFont {
    return UIFont.customFont(size: px*0.75)
}

func SM_CBFont(_ px:CGFloat) -> UIFont {
    return UIFont.customBoldFont(size: px*0.75)
}

func SM_CEBFont(_ px:CGFloat) -> UIFont {
    return UIFont.customEspecialBoldFont(size: px*0.75)
}

func SM_HEXCOLOR(_ hex:String) -> UIColor {
    return UIColor.color(with: hex)
}

struct BillType: BaseModel {
    var title:String?
    var type:String?
}

let SM_SONG_FAVORITE_LIST_DID_CHANGE_NOTIFICATION = "SM_SONG_FAVORITE_LIST_DID_CHANGE_NOTIFICATION"

func SMNAVI_PRESENT(_ controller:UIViewController) {
    let baseNavi = SMNavigator.sharedInstance().lastNavigationController()
    let targetNavi = BaseNavigationController.init(rootViewController: controller)
    SMNavigator.sharedInstance().appendPresent(targetNavi)
    baseNavi.present(targetNavi, animated: true) {

    }
}

func SMNAVI_PUSH(_ controller:UIViewController) {
    let baseNavi = SMNavigator.sharedInstance().lastNavigationController()
    baseNavi.pushViewController(controller, animated: true)
}

func SMNAVI_POP() {
    SMNavigator.sharedInstance().lastNavigationController().popViewController(animated: true)
}

func SMNAVI_DISMISS(_ callback:@escaping (()->())) -> Void {
    SMNavigator.sharedInstance().lastNavigationController().dismiss(animated: true, completion: callback)
    SMNavigator.sharedInstance().removePresent()
}

let singleton = SMNavigator.init()
open class SMNavigator:NSObject {

    var navigationControllers = [BaseNavigationController]()

    override init() {
        super.init()
        self.navigationControllers.append((UIApplication.shared.keyWindow?.rootViewController)! as! BaseNavigationController)
    }

    func appendPresent(_ navigationController:BaseNavigationController) {
        self.navigationControllers.append(navigationController)
    }

    func removePresent() {
        self.navigationControllers.removeLast()
    }

    func lastNavigationController() -> BaseNavigationController {
        return self.navigationControllers.last!
    }

    class func sharedInstance() -> SMNavigator {
        return singleton
    }
}





